<?php 
if(!isset($_SESSION)) 
{ 
session_start(); 
} 

$sqldeparment = mysql_query("SELECT dl.IDDepartment,dl.DepartmentName FROM department_lang dl WHERE dl.LangID='".$_SESSION['lang']."' ORDER BY dl.IDDepartment;");

$sqlrole = mysql_query("SELECT IDRole,Description from roles ORDER BY IDRole desc");

$sqlsex = mysql_query("select ac_sex.SexID,ac_sex_lang.SexName  from ac_sex , ac_sex_lang	where ac_sex.SexID=ac_sex_lang.SexID 
			            				and ac_sex_lang.LangID='".$_SESSION['lang']."'");

$sqltypeemp = mysql_query("select tyemp.IDTypeEmpl,typlang.TypeEmplName from type_employee tyemp,type_employee_lang typlang
					where tyemp.IDTypeEmpl = typlang.IDTypeEmpl and typlang.IDLang='".$_SESSION['lang']."' AND tyemp.IDTypeEmpl != 3");
?>
<link  href="admin/css/jsDatePick_ltr.min.css" rel="stylesheet" type="text/css" media="all" />
<script type="text/javascript" src="admin/css/jsDatePick.min.1.3.js"></script>
<script type="text/javascript">
window.onload = function(){
	new JsDatePick({
		useMode:2,
		target:"birthday",

		dateFormat:"%Y-%m-%d"
	});
	new JsDatePick({
		useMode:2,
		target:"startwork",

		dateFormat:"%Y-%m-%d"
	});
};

function validate(){
	var username = document.getElementById("username").value;
	var password = document.getElementById("pass").value; 
	var repassword = document.getElementById("repass").value;

	if(username.length==0){
		alert('<?=$l_alertusername?>');
		return false;
	}else if(password.length == 0){
		alert('<?=$l_alertinputpass?>');
		return false;
	}else if(repassword.length == 0){
		alert('<?=$l_alertrepass?>');
		return false;
	}
	else if(password != repassword){
		alert('<?=$l_alertpassandrepass?>');
		return false;
	}else{
		checkExist();
	}
}

function checkExist(){
	var username = document.getElementById("username").value;
	var password = document.getElementById("pass").value; 
	var repassword = document.getElementById("repass").value;

	var fulln = document.getElementById("fulln").value;
	var employeeCode = document.getElementById("employeeCode").value; 
	var identity = document.getElementById("identity").value;

	var bankName = document.getElementById("bankName").value;
	var bankAccount = document.getElementById("bankAccount").value; 
	var birthday = document.getElementById("birthday").value;

	var sex = document.getElementById("sex").value;
	var startwork = document.getElementById("startwork").value; 
	var mail = document.getElementById("mail").value;

	var mobile = document.getElementById("mobile").value;
	var phone = document.getElementById("phone").value; 
	var address = document.getElementById("address").value;
	var typeempl = document.getElementById("typeemployee").value;

	var department = document.getElementById("department").value;
	var roleaccess = document.getElementById("roleaccess").value; 
	var position = document.getElementById("position").value;

	var accountant = document.getElementById("accountant").value;
	var currentJob = document.getElementById("currentJob").value; 
	var description = document.getElementById("description").value; 
	
	if (window.XMLHttpRequest){// code for IE7+, Firefox, Chrome, Opera, Safari
		xmlhttp=new XMLHttpRequest();
	}else{// code for IE6, IE5
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	xmlhttp.onreadystatechange=function(){
										  if (xmlhttp.readyState==4 && xmlhttp.status==200){
										    	document.getElementById("idcheckdb_username").innerHTML=xmlhttp.responseText;
										    	var lang = '<?=$_SESSION['lang']?>';
										    	$.ajax({url:"admin/employeemanagement/ajaxviewresultcreateempl.php?newlang="+lang,success:function(result){
													$("#idcheckdb_username").html(result);
													var thongbao=document.getElementById("viewcheckdb_username").value;
													if(thongbao=="okk"){
													//	alert(thongbao);
														//if (window.XMLHttpRequest){// code for IE7+, Firefox, Chrome, Opera, Safari
														//	xmlhttp=new XMLHttpRequest();
														//}else{// code for IE6, IE5
														//	xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
													//	}
													//	xmlhttp.onreadystatechange=function(){
													//		 if (xmlhttp.readyState==4 && xmlhttp.status==200){
													//		 	document.getElementById("tbcomp").innerHTML=xmlhttp.responseText;
													//			reset();
													//		 }
													//	}
														//xmlhttp.open("GET","admin/employeemanagement/ajaxprocessaddempl.php?register=add&username="+username+"&password="+password+"&fulln="+fulln+"&employeeCode="+employeeCode+"&identity="+identity+"&bankName="+bankName+"&bankAccount="+bankAccount+"&birthday="+birthday+"&sex="+sex+"&startwork="+startwork+"&mail="+mail+"&mobile="+mobile+"&phone="+phone+"&address="+address+"&department="+department+"&roleaccess="+roleaccess+"&position="+position+"&accountant="+accountant+"&currentJob="+currentJob+"&description="+description,true);
														//xmlhttp.send();
														window.location.assign("admin/employeemanagement/ajaxprocessaddempl.php?register=add&username="+username+"&password="+password+"&fulln="+fulln+"&employeeCode="+employeeCode+"&identity="+identity+"&bankName="+bankName+"&bankAccount="+bankAccount+"&birthday="+birthday+"&sex="+sex+"&startwork="+startwork+"&mail="+mail+"&mobile="+mobile+"&phone="+phone+"&address="+address+"&department="+department+"&roleaccess="+roleaccess+"&position="+position+"&accountant="+accountant+"&currentJob="+currentJob+"&description="+description+"&typeempl="+typeempl);
													}else{
														alert(thongbao);
														//return false;
													}
										    	}});
										    	
										  }
									  }
	xmlhttp.open("GET","admin/employeemanagement/ajaxcheckexistdb_username.php?usname="+username,true);
	xmlhttp.send();
}

function reset(){
	document.getElementById("username").value="";
	document.getElementById("pass").value ="";
	document.getElementById("repass").value ="";
	document.getElementById("fulln").value ="";
	document.getElementById("employeeCode").value ="";
	document.getElementById("identity").value ="";
	document.getElementById("bankName").value ="";
	document.getElementById("bankAccount").value ="";
	document.getElementById("birthday").value ="";
	document.getElementById("startwork").value ="";
	document.getElementById("mail").value ="";
	document.getElementById("mobile").value ="";
	document.getElementById("phone").value ="";
	document.getElementById("address").value ="";
	document.getElementById("position").value ="";
	document.getElementById("currentJob").value ="";
	document.getElementById("description").value ="";
}

</script>

<div id="contains" style="background-color: #edf4f7;">

	<div class="title"></div>
	<div class="body">
	<form action="admin/employeemanagement/process-create-new-account.php" id="formregister" method="get" onsubmit="return validate();">
		<div id="storeForm" style="margin-left: 5px;">
		<div id="idcheckdb_username">
			<input type="hidden" id="viewcheckdb_username" value="<?=$_SESSION['checkdb_username']?>" />
		</div>
			<span id="head"><?=$l_createaccount?></span>
			<div id="content">
			<span
					style="padding: 3px 3px 0px 3px; color: #508E21;"> <?=$l_personaldetail?>
				</span>
				<table style="border-top: 1px dotted silver;width: 100%;">
					<tr>
						<td width="15%" class="tdFirst"><?=$l_username?> :</td>
						<td width="35%"><input id="username" name="username" type="text"
							value="" maxlength="20" style="width: 100%;" autocomplete="off"
							class="textfiledCompany" /></td>
						<td width="15%" class="tdFirst"><?=$l_fullname?> :</td>
						<td width="35%"><input id="fulln" name="fulln" type="text"
							value="" maxlength="100" style="width: 100%;" autocomplete="off"
							class="textfiledCompany" />
						</td>
					</tr>
					<tr>
						<td width="15%" class="tdFirst"><?=$l_password?> :</td>
						<td width="35%"><input type="password" id="pass" name="pass" value=""
							maxlength="20" style="width: 100%;" class="textfiledCompany" autocomplete="off"/></td>
						<td width="150px" class="tdFirst"><?=$l_retypepassword?> :</td>
						<td width="35%"><input type="password" id="repass" name="repass"
							maxlength="20" style="width: 100%;" class="textfiledCompany" autocomplete="off"/>
						</td>
					</tr>
					<tr>
						<td width="150px" class="tdFirst"><?=$l_employeecode?> :</td>
						<td width="35%"><input id="employeeCode" name="employeeCode"
							type="text" value="" maxlength="20" style="width: 100%;"
							class="textfiledCompany" /></td>
						<td width="150px" class="tdFirst"><?=$l_cmnd?> :</td>
						<td width="35%"><input id="identity" name="identity" type="text"
							value="" maxlength="50" style="width: 100%;"
							class="textfiledCompany" />
						</td>
					</tr>
					<tr>
						<td width="15%" class="tdFirst"><?=$l_bankname?> :</td>
						<td width="35%"><input id="bankName" name="bankName" type="text"
							value="" maxlength="50" style="width: 100%;"
							class="textfiledCompany" /></td>
						<td width="15%" class="tdFirst"><?=$l_bankaccount ?> :</td>
						<td width="35%"><input id="bankAccount" name="bankAccount"
							type="text" value="" maxlength="50" style="width: 100%;"
							class="textfiledCompany" />
						</td>
					</tr>
					<tr>
						<td width="15%" class="tdFirst"><?=$l_birthday?> :</td>
						<td width="35%"><span><span>
							<input id="birthday" name="birthday"
								type="text" value="" maxlength="50" style="width: 100%;"
								class="textfiledCompany" /></span> </span></td>
						<td width="15%" class="tdFirst"><?=$l_sex?> :</td>
						<td width="35%"><select id="sex" name="sex" size="1"
							style="width: 100%;height: 22px;">
							<?php while ($row = mysql_fetch_array($sqlsex)){?>
								<option value="<?=$row[SexID]?>" id="<?=$row[SexID]?>"><?php echo $row[SexName];?></option>
								<?php }?>
						</select></td>
					</tr>
					<tr>
						<td width="15%" class="tdFirst"><?=$l_startwork?> :</td>
						<td width="35%"><span style="z-index: 1;"><span style="white-space: nowrap;">
							 <input id="startwork" name="startwork"
								type="text" value="" maxlength="50" style="width: 100%;"
								class="textfiledCompany" /> </span> </span></td>

						<td width="15%" class="tdFirst"><?=$l_email?> :</td>
						<td width="35%"><input id="mail" name="mail" type="text"
							maxlength="200" style="width: 100%;" class="textfiledCompany" />
						</td>
					</tr>
					<tr>
						<td width="15%" class="tdFirst"><?=$l_mobile?> :</td>
						<td width="35%"><input id="mobile" name="mobile" type="text"
							maxlength="30" style="width: 100%;" class="textfiledCompany" />
						</td>
						<td width="15%" class="tdFirst"><?=$l_phone?> :</td>
						<td width="35%"><input id="phone" name="phone" type="text"
							maxlength="20" style="width: 100%;" class="textfiledCompany" /></td>
					</tr>
					<tr>
						<td width="15%" class="tdFirst"><?=$l_address?> :</td>
						<td width="35%"><textarea id="address" name="address" 
							style="width: 100%;min-height: 43px;" class="textareaEmp" ></textarea>
						</td>
						
						<td width="15%" class="tdFirst"><?=$l_type_employee?> :</td>
						<td width="35%">
							<select id="typeemployee" name="typeemployee" size="1"
								style="width: 100%;height: 22px;">
								<?php while ($rowtype = mysql_fetch_array($sqltypeemp)){?>
									<option value="<?=$rowtype[IDTypeEmpl]?>" id="<?=$rowtype[IDTypeEmpl]?>"><?php echo $rowtype[TypeEmplName];?></option>
									<?php }?>
							</select>
						</td>
					</tr>
				</table>
				<span
					style="border-bottom: 1px dotted silver; display: block; padding: 3px 3px 0px 3px; color: #508E21;">
					<?=$l_positioninfo?> </span>
				
				<table style="width: 100%;">
					<tr >
						<td width="15%" class="tdFirst"><?=$l_department?> :</td>
						<td width="35%"><select id="department" name="department" size="1"
							style="width: 100%;height: 22px;">
							<?php while($row=mysql_fetch_array($sqldeparment)){?>
								<option value="<?=$row[IDDepartment]?>" id="<?=$row[IDDepartment]?>"><?php echo $row['DepartmentName']?></option>
								<?php }?>
						</select></td>
						<td width="15%" class="tdFirst"><?=$l_accessright?> :</td>
						<td width="35%"><select id="roleaccess" name="roleaccess" size="1"
							style="width: 100%;height: 22px;">
							<?php while ($rowrole = mysql_fetch_array($sqlrole)){?>
								<option value="<?=$rowrole[IDRole]?>" id="<?=$rowrole[IDRole]?>"><?php echo $rowrole[Description];?></option>
								<?php }?>
						</select></td>
					</tr>
					<tr>
						<td width="15%" class="tdFirst"><?=$l_position?> :</td>
						<td width="35%"><input id="position" name="position" type="text"
							maxlength="200" style="width: 100%;" class="textfiledCompany" />
						</td>
						<td class="tdFirst" width="15%"><?=$l_accountant?> :</td>
						<td width="35%"><table style="width: 100px">
								<tr>
									<td><input id="accountant" type="radio" name="accountant" value="1" /><label>
											<?=$l_yes?></label></td>
									<td><input id="accountant" type="radio" name="accountant" checked="checked"
										value="0" /><label> <?=$l_No?></label></td>
								</tr>
							</table></td>
					</tr>
					<tr>
						<td valign="top" width="15%" class="tdFirst"><?=$l_responsibilities?> :</td>
						<td colspan="3"><input id="currentJob" name="currentJob"
							type="text" maxlength="100" style="width: 515px"
							class="textfiledCompany" /></td>
					</tr>
					<tr>
						<td valign="top" width="15%" class="tdFirst"><?=$l_description?> :</td>
						<td colspan="3"><textarea id="description" name="description"
								class="textareaEmp"></textarea></td>
					</tr>
				</table>
				<span
					style="border-top: 1px dotted silver; display: block; height: 2px;"></span>
				<div style="text-align: right; margin-top: 10px">
					<input id="register" name="register" type="button" value="<?=$l_register?>" 
						class="buttonNormal" onclick="validate();"/> 
					<input id="reset" name="reset" onclick="reset();"
						type="reset" value="<?=$l_reset?>" class="buttonNormal" />
				</div>
			</div>
		</div>
</form>
	</div>
</div>
